package com.gaogzhen.algorithm.leetCode;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

public class LengthOfLongestSubstring {
    public static int lengthOfLongestSubstring(String s) {
        int l;
        if (s == null || (l = s.length()) == 0)
            return 0;
        int count = 0;
        LinkedList<Character> list = new LinkedList<>();

            for (int i = 0; i < l && count < (l - i + list.size()); i++) {
                char c = s.charAt(i);
                if (list.contains(c)) {
                    count = Math.max(count, list.size());
                    list.pop();
                }
                list.addLast(c);
            }
            count = Math.max(count, list.size());
            list.clear();

        return count;
    }
}
